package com.yingsheng.bi.hks.config;

import com.yingsheng.bi.hks.template.biz.AccessTokenProcessor;
import com.yingsheng.bi.hks.template.biz.PermissionProcessor;
import com.yingsheng.bi.hks.template.controller.IControllerTemplate;
import com.yingsheng.bi.hks.template.controller.SimpleControllerTemplate;
import com.yingsheng.bi.hks.template.controller.processor.HttpInputMessageProcessor;
import com.yingsheng.bi.hks.template.controller.processor.JsonRequestBodyProcessor;
import com.yingsheng.bi.hks.template.element.SmsCodeVerifyElementProcessor;
import com.yingsheng.bi.hks.template.processor.OrderedProcessors;
import com.yingsheng.bi.hks.template.processor.Processors;
import com.yingsheng.bi.hks.template.processor.impl.*;
import com.yingsheng.bi.hks.template.biz.BusinessInsertProcessor;
import com.yingsheng.bi.hks.template.biz.BusinessUpdateProcessor;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class TemplateConfiguration {

    @Bean
    public SmsCodeVerifyElementProcessor smsCodeVerify() {
        return new SmsCodeVerifyElementProcessor();
    }

    @Bean
    public PermissionProcessor permissionProcessor() {
        return new PermissionProcessor();
    }

    @Bean
    public AccessTokenProcessor accessTokenProcessor() {
        return new AccessTokenProcessor();
    }

    @Bean
    public OrderedProcessors accessEntryProcessor() {
        OrderedProcessors orderedProcessors = new OrderedProcessors();
        orderedProcessors.addProcessor(accessTokenProcessor());
        orderedProcessors.addProcessor(permissionProcessor());
        return orderedProcessors;
    }

    @Bean
    public IControllerTemplate publicQueryTemplate(ApplicationContext applicationContext) {

        DtoElementProcessor dtoElementProcessor = new DtoElementProcessor();
        FieldElementProcessor fieldElementProcessor = new FieldElementProcessor();
        fieldElementProcessor.setApplicationContext(applicationContext);
        fieldElementProcessor.setInnerLogic(dtoElementProcessor);
        dtoElementProcessor.setInnerLogic(fieldElementProcessor);

        Request2MapProcessor entry1 = new Request2MapProcessor();
        RequestFieldProcessor entry2 = new RequestFieldProcessor();
        BusinessInsertProcessor entry3 = new BusinessInsertProcessor();
        entry2.setInnerLogic(dtoElementProcessor);

        Processors entrys = new Processors();
        entrys.addProcessor(entry1);
        entrys.addProcessor(entry2);
        entrys.addProcessor(entry3);

        Response2MapProcessor exit1 = new Response2MapProcessor();
        ResponseFieldProcessor exit2 = new ResponseFieldProcessor();
        exit2.setInnerLogic(dtoElementProcessor);
        BusinessUpdateProcessor exit3 = new BusinessUpdateProcessor();

        OrderedProcessors exits = new OrderedProcessors();
        exits.addProcessor(exit1);
        exits.addProcessor(exit2);
        exits.addProcessor(exit3);
        exits.afterPropertiesSet();

        SimpleControllerTemplate template = new SimpleControllerTemplate();
        template.setEntryLogic(entrys);
        template.setExitLogic(exits);
        return template;
    }

    @Bean
    public IControllerTemplate publicTransTemplate(ApplicationContext applicationContext) {

        DtoElementProcessor dtoElementProcessor = new DtoElementProcessor();
        FieldElementProcessor fieldElementProcessor = new FieldElementProcessor();
        fieldElementProcessor.setApplicationContext(applicationContext);
        fieldElementProcessor.setInnerLogic(dtoElementProcessor);
        dtoElementProcessor.setInnerLogic(fieldElementProcessor);

        Request2MapProcessor entry1 = new Request2MapProcessor();
        RequestFieldProcessor entry2 = new RequestFieldProcessor();
        BusinessInsertProcessor entry3 = new BusinessInsertProcessor();
        entry2.setInnerLogic(dtoElementProcessor);

        Processors entrys = new Processors();
        entrys.addProcessor(entry1);
        entrys.addProcessor(entry2);
        entrys.addProcessor(entry3);

        Response2MapProcessor exit1 = new Response2MapProcessor();
        ResponseFieldProcessor exit2 = new ResponseFieldProcessor();
        exit2.setInnerLogic(dtoElementProcessor);
        BusinessUpdateProcessor exit3 = new BusinessUpdateProcessor();

        OrderedProcessors exits = new OrderedProcessors();
        exits.addProcessor(exit1);
        exits.addProcessor(exit2);
        exits.addProcessor(exit3);
        exits.afterPropertiesSet();

        SimpleControllerTemplate template = new SimpleControllerTemplate();
        template.setEntryLogic(entrys);
        template.setExitLogic(exits);
        return template;
    }

    @Bean
    public IControllerTemplate accessQueryTemplate(ApplicationContext applicationContext) {

        DtoElementProcessor dtoElementProcessor = new DtoElementProcessor();
        FieldElementProcessor fieldElementProcessor = new FieldElementProcessor();
        fieldElementProcessor.setApplicationContext(applicationContext);
        fieldElementProcessor.setInnerLogic(dtoElementProcessor);
        dtoElementProcessor.setInnerLogic(fieldElementProcessor);

        Request2MapProcessor entry1 = new Request2MapProcessor();
        RequestFieldProcessor entry2 = new RequestFieldProcessor();
        BusinessInsertProcessor entry3 = new BusinessInsertProcessor();
        entry2.setInnerLogic(dtoElementProcessor);

        Processors entrys = new Processors();
        entrys.addProcessor(entry1);
        entrys.addProcessor(entry2);
        entrys.addProcessor(accessEntryProcessor());
        entrys.addProcessor(entry3);

        Response2MapProcessor exit1 = new Response2MapProcessor();
        ResponseFieldProcessor exit2 = new ResponseFieldProcessor();
        exit2.setInnerLogic(dtoElementProcessor);
        BusinessUpdateProcessor exit3 = new BusinessUpdateProcessor();

        OrderedProcessors exits = new OrderedProcessors();
        exits.addProcessor(exit1);
        exits.addProcessor(exit2);
        exits.addProcessor(exit3);
        exits.afterPropertiesSet();

        SimpleControllerTemplate template = new SimpleControllerTemplate();
        template.setEntryLogic(entrys);
        template.setExitLogic(exits);
        return template;
    }

    @Bean
    public IControllerTemplate accessTransTemplate(ApplicationContext applicationContext) {

        DtoElementProcessor dtoElementProcessor = new DtoElementProcessor();
        FieldElementProcessor fieldElementProcessor = new FieldElementProcessor();
        fieldElementProcessor.setApplicationContext(applicationContext);
        fieldElementProcessor.setInnerLogic(dtoElementProcessor);
        dtoElementProcessor.setInnerLogic(fieldElementProcessor);

        Request2MapProcessor entry1 = new Request2MapProcessor();
        RequestFieldProcessor entry2 = new RequestFieldProcessor();
        BusinessInsertProcessor entry3 = new BusinessInsertProcessor();
        entry2.setInnerLogic(dtoElementProcessor);

        Processors entrys = new Processors();
        entrys.addProcessor(entry1);
        entrys.addProcessor(entry2);
        entrys.addProcessor(accessEntryProcessor());
        entrys.addProcessor(entry3);

        Response2MapProcessor exit1 = new Response2MapProcessor();
        ResponseFieldProcessor exit2 = new ResponseFieldProcessor();
        exit2.setInnerLogic(dtoElementProcessor);
        BusinessUpdateProcessor exit3 = new BusinessUpdateProcessor();

        OrderedProcessors exits = new OrderedProcessors();
        exits.addProcessor(exit1);
        exits.addProcessor(exit2);
        exits.addProcessor(exit3);
        exits.afterPropertiesSet();

        SimpleControllerTemplate template = new SimpleControllerTemplate();
        template.setEntryLogic(entrys);
        template.setExitLogic(exits);
        return template;
    }

    @Bean
    public IControllerTemplate qiYueSuoTemplate(ApplicationContext applicationContext) {
        QiYueSuoNotifyDecodeProcessor init111 = new QiYueSuoNotifyDecodeProcessor();
        JsonRequestBodyProcessor init11 = new JsonRequestBodyProcessor();
        init11.setInnerLogic(init111);
        HttpInputMessageProcessor init1 = new HttpInputMessageProcessor();
        init1.setInnerLogic(init11);
        Processors inits = new Processors();
        inits.addProcessor(init1);

        DtoElementProcessor dtoElementProcessor = new DtoElementProcessor();
        FieldElementProcessor fieldElementProcessor = new FieldElementProcessor();
        fieldElementProcessor.setApplicationContext(applicationContext);
        fieldElementProcessor.setInnerLogic(dtoElementProcessor);
        dtoElementProcessor.setInnerLogic(fieldElementProcessor);

        Request2MapProcessor entry1 = new Request2MapProcessor();
        RequestFieldProcessor entry2 = new RequestFieldProcessor();
        BusinessInsertProcessor entry3 = new BusinessInsertProcessor();
        entry2.setInnerLogic(dtoElementProcessor);

        Processors entrys = new Processors();
        entrys.addProcessor(entry1);
        entrys.addProcessor(entry2);
        entrys.addProcessor(entry3);

        Response2MapProcessor exit1 = new Response2MapProcessor();
        ResponseFieldProcessor exit2 = new ResponseFieldProcessor();
        exit2.setInnerLogic(dtoElementProcessor);
        BusinessUpdateProcessor exit3 = new BusinessUpdateProcessor();

        OrderedProcessors exits = new OrderedProcessors();
        exits.addProcessor(exit1);
        exits.addProcessor(exit2);
        exits.addProcessor(exit3);
        exits.afterPropertiesSet();

        SimpleControllerTemplate template = new SimpleControllerTemplate();
        template.setInitLogic(inits);
        template.setEntryLogic(entrys);
        template.setExitLogic(exits);
        return template;
    }
}
